minimize total length of pipe